package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Slf4j
@Api(tags = "管理端-订单接口")
public class OrderController {

    @Autowired
    OrderService orderService;

    /**
     * 订单展示
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation(value = "订单展示")
    public Result<PageResult> getConditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        PageResult p=orderService.getConditionSearchPage(ordersPageQueryDTO);
        return Result.success(p);
    }


    /**
     * 查询订单详情
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    @ApiOperation(value = "查询订单详情")
    public Result<OrderVO> getDetails(@PathVariable Long id) {
        OrderVO orderVO=orderService.getDetailsAdmin(id);
        return Result.success(orderVO);
    }


    /**
     * 各个状态的订单数量统计
     * @return
     */
    @GetMapping("/statistics")
    @ApiOperation(value = "各个状态的订单数量统计")
    public Result<OrderStatisticsVO> getStatistics() {
        OrderStatisticsVO orderStatisticsVO=orderService.getStatistics();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 接单
     * @param ordersConfirmDTO
     * @return
     */
    @PutMapping("/confirm")
    @ApiOperation(value = "接单接口")
    public Result confirmOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO) {

        orderService.confirmOrder(ordersConfirmDTO.getId());

        return Result.success();
    }


    /**
     * 拒单
     * @param ordersRejectionDTO
     * @return
     */
    @PutMapping("/rejection")
    public Result rejectionOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) {
        orderService.rejectionOrder(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 商家端取消订单
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("/cancel")
    public Result cancelOrder(@RequestBody OrdersCancelDTO ordersCancelDTO) {
        orderService.cancelOrderAdmin(ordersCancelDTO);
        return Result.success();
    }


    @PutMapping("/delivery/{id}")
    public Result deliveryOrder(@PathVariable Long id) {
        orderService.deliveryOrder(id);

        return Result.success();
    }


    /**
     * 完成订单
     *
     * @return
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("完成订单")
    public Result complete(@PathVariable("id") Long id) {
        int[] s=new int[10];
        orderService.complete(id);
        return Result.success();
    }



}
